package xyz.xtt.pay.service;

import java.util.List;

import com.baomidou.mybatisplus.extension.service.IService;

import xyz.xtt.pay.api.enums.PayOrderBusinessTypeEnum;
import xyz.xtt.pay.api.enums.PayOrderStatusEnum;
import xyz.xtt.pay.client.request.FetchUnPaidOrdersRequest;
import xyz.xtt.pay.client.response.PayOrderResponse;
import xyz.xtt.pay.client.response.TblPayOrderDto;
import xyz.xtt.pay.entity.TblPayOrder;

public interface ITblPayOrderService extends IService<TblPayOrder> {
	/**
	 * 根据业务类型和业务关联id获取支付订单
	 * 
	 * @param payOrderBusinessTypeEnum
	 * @param businessRefId
	 * @return
	 */
	TblPayOrder getByBusiness(PayOrderBusinessTypeEnum payOrderBusinessTypeEnum, String businessRefId);

	/**
	 * 更新支付订单状态
	 * 
	 * @param payOrderId 支付单id
	 * @param oldStatus  支付单当前状态
	 * @param newStatus  支付单新状态
	 * @return
	 */
	boolean updatePayStatus(Long payOrderId, PayOrderStatusEnum oldStatus, PayOrderStatusEnum newStatus);

	/**
	 * 批量查询待支付订单
	 * 
	 * @param fetchSize 请求数量
	 * @return 待支付订单集合
	 */
	List<TblPayOrderDto> fetchUnPaidOrders(FetchUnPaidOrdersRequest fetchSize);

	/**
	 * 查询订单
	 * 
	 * @param payOrderId
	 * @param appUserId
	 * @return
	 */
	TblPayOrder getPayOrder(Long payOrderId, Long appUserId);

	/**
	 * 更新支付成功
	 * 
	 * @param payOrderId
	 * @return
	 */
	boolean updatePaySuccess(Long payOrderId);

	/**
	 * 铸造后更新交易单号
	 * 
	 * @param id
	 * @param transactionOrderId
	 * @return
	 */
	boolean mintAfterUpdateResult(Long id, Long transactionOrderId);

	/**
	 * 查询支付订单
	 * 
	 * @param payOrderId
	 * @return
	 */
	TblPayOrderDto fetchPayOrder(Long payOrderId);

	/**
	 * 更新支付订单业务附加信息
	 * 
	 * @param payOrderId
	 * @param jsonStr
	 */
	void updatePayOrderBusinessAttach(long payOrderId, String jsonStr);

	/**
	 * 根据业务订单id查询支付订单
	 * 
	 * @param businessOrderId
	 * @return
	 */
	TblPayOrder getPayOrderByBusinessOrder(Long businessOrderId);

	/**
	 * 根据支付订单id查询支付订单(加锁)
	 * 
	 * @param payOrderId
	 * @return
	 */
	TblPayOrder getByIdForUpdate(Long payOrderId);

	/**
	 * 根据业务订单id查询支付订单(加锁)
	 * 
	 * @param businessOrderId
	 * @return
	 */
	TblPayOrder getByBusinessOrderIdForUpdate(Long businessOrderId);

	boolean updatePayCancel(Long payOrderId, String reasonRemark);

	TblPayOrder getPayOrderByBusinessOrder4Update(Long businessOrderId);

	boolean updatePaySuccess(Long payOrderId, String thirdTradeNo, Integer payMode, Integer payModeSub);

	/**
	 * 根据审核ID 查询支付状态
	 *
	 * @param auditId
	 * @return
	 */
	PayOrderResponse infoPayOrderWithBusinessRefId(String businessRefId, PayOrderBusinessTypeEnum businessType);
}
